<?php
$this->breadcrumbs = array(
    '配置管理'
);
?>
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'search-form',
    'type' => 'search',
    'method' => 'GET',
    'htmlOptions' => array('class' => 'navbar-search pull-left', 'style' => 'margin:0;width:100%;'),
));
?>
<?php
$columns = array(
    array('header' => '类型', 'name' => 'type', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:10%'), 'headerHtmlOptions' => array('style' => 'width:10%')),
    array('header' => '名称', 'name' => 'name', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:15%'), 'headerHtmlOptions' => array('style' => 'width:15%')),
    array('header' => '配置', 'name' => 'config', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:40%'), 'headerHtmlOptions' => array('style' => 'width:40%')),
    array('header' => '状态', 'name' => 'status', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:10%'), 'headerHtmlOptions' => array('style' => 'width:10%')),
    array('header' => '执行等级', 'name' => 'level', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:10%'), 'headerHtmlOptions' => array('style' => 'width:10%')),
    array('header' => '重试', 'name' => 'try', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:10%'), 'headerHtmlOptions' => array('style' => 'width:10%')),
    array('header' => '操作', 'name' => 'button', 'value' => array($this, 'colRevise'), 'type' => 'raw', 'htmlOptions' => array('style' => 'width:5%'), 'headerHtmlOptions' => array('style' => 'width:5%')),
)

?>
<div style="min-height:300px;">
    <ul class="nav nav-tabs" role="tablist" id="myTab">
        <li role="presentation" class="active"><a href="#channel" role="tab" data-toggle="tab">通道配置</a></li>
        <li role="presentation"><a href="#global" role="tab" data-toggle="tab">全局配置</a></li>
        <li role="presentation"><a href="#app" role="tab" data-toggle="tab">应用配置</a></li>
    </ul>

    <div class="tab-content">
        <div class="tab-pane active" id="channel">
            <div class="submenu">
                <div class="row">
                    <div class="col-md-2">
                        <?php
                        echo $form->dropDownList($model, 'type', MsggItem::getOptions('type', array('' => '==通道类型==')), array('class' => 'form-control'));
                        ?>
                    </div>
                    <div class="col-md-2">
                        <?php
                        echo $form->dropDownList($model, 'status', MsggConfig::getOptions('status', array('' => '==配置状态==')), array('class' => 'form-control'));
                        ?>
                    </div>
                    <div class="col-md-4">
                        <?php
                        echo $form->textFieldRow($model, 'searchKey', array('class' => 'form-control'));
                        ?>
                    </div>
                    <div class="col-md-2">
                        <button class="btn btn-primary" style="width:100%;" type="submit" name="yt0"><i
                                    class="fa fa-search"></i>
                        </button>
                    </div>
                    <div class="col-md-2">
                        <?php
                        $this->widget('bootstrap.widgets.TbButton', array(
                            'label' => '新增',
                            'htmlOptions' => array('class' => 'pull-right btn-success', 'style' => 'width:100%'),
                            'url' => $this->createUrl('create',['type'=>'channel']),
                        ));
                        ?>
                    </div>
                </div>

            </div>
            <?php
            $this->widget('bootstrap.widgets.TbGridView', array(
                'id' => 'model-channel',
                'ajaxVar' => null,
                'type' => array('striped'),
                'hideHeader' => false,
                'dataProvider' => $model->searchByReader(new ChannelConfigReader()),
                'columns' => $columns,
            ));
            ?>
        </div>
        <div class="tab-pane" id="global">
            <?php
            $this->widget('bootstrap.widgets.TbGridView', array(
                'id' => 'model-global',
                'ajaxVar' => null,
                'type' => array('striped'),
                'hideHeader' => false,
                'dataProvider' => $model->searchByReader(new MsggGlobalReader()),
                'columns' => $columns,
            ));
            ?>
        </div>
        <div class="tab-pane" id="app">
            <div id="report-ontime" style="min-height: 300px">
                <?php
                $this->widget('bootstrap.widgets.TbGridView', array(
                    'id' => 'model-app',
                    'ajaxVar' => null,
                    'type' => array('striped'),
                    'hideHeader' => false,
                    'dataProvider' => $model->searchByReader(new AppConfigReader()),
                    'columns' => $columns,
                ));
                ?>
            </div>
        </div>
    </div>
</div>


<?php
$this->endWidget();
?>
<script type="text/javascript">
    $(function ($) {
        $(document).on('click', 'a.delete', function () {
            if (!confirm('确定删除?')) return false;
            var th = this;
            var afterDelete = function () {
            };
            var type = $(this).attr('type');
            var id = '';
            if (type == 'app' || type == 'global') {
                id = 'model-' + type;
            }
            else {
                id = 'model-channel';
            }
            $.fn.yiiGridView.update(id, {
                type: 'GET',
                url: $(this).attr('href'),
                ajaxUpdate: false,
                success: function (data) {
                    if (data == 'Success') {
                        $.fn.yiiGridView.update(id);
                        alert('success');
                    } else {
                        alert(data);
                    }
                    afterDelete(th, true, data);
                },
                error: function (XHR) {
                    return afterDelete(th, false, XHR);
                }
            });
            return false;
        });
    });
</script>







